@isTest
private class ImportObjectTest {
    static testMethod void testMethod1() {
        Account acc = TestUtils.createAccount();
        acc.Level__c = '一级医院';
        insert acc;
        
        ProductStructure__c ps = new ProductStructure__c();
        ps.Classify3__c = '试剂';
        insert ps;
        Product__c p1 = TestUtils.createProduct();
        p1.ProductName__c = '尿有形成份检测稀释液UPS';
        p1.Category0__c = '试剂';
        p1.ProductStructure__c = ps.Id;
        p1.PriceCompany__c = 'MKSY';
        p1.NCCode__c = '000001';
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        
        Product__c p2 = TestUtils.createProduct();
        p2.Category0__c = '试剂';
        p2.ProductStructure__c = ps.Id;
        p2.PriceCompany__c = 'MKSY';
        p2.NCCode__c = '000002';
        p2.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        insert new Product__c[] {p1, p2};

        Price__c pr1 = new Price__c(

            Product__c = p1.Id,
            Company__c = '四川省迈克实业有限公司',
            CompanyBottomPrice__c = 1.0,
            HospitalBottomPrice__c = 1.0,
            InvoiceDealerPrice__c = 1.0,
            AreaDealerPrice__c = 1.0,
            MarketPrice__c = 1.0,
            HospitalManagerPrice__c= 1.0,
            InstCost__c = 0.5
            
        );
        Price__c pr2 = new Price__c(
            Product__c = p2.Id,
            Company__c = '四川省迈克实业有限公司',
            CompanyBottomPrice__c = 2.0,
            HospitalBottomPrice__c = 1.0,
            InvoiceDealerPrice__c = 2.0,
            AreaDealerPrice__c = 1.0,
            MarketPrice__c = 1.0,
            HospitalManagerPrice__c= 1.0,
            InstCost__c = 0.5
            
        );
        insert new Price__c[] {pr1,pr2};
        
           /// 日期处理
        Integer m = Date.today().month(); //当前月份
        Integer y = Date.today().year();  //当前年份 
       ///取上月
         if(m == 1){
        m = 12 ;
            y -= 1;
        }else{
        m -= 1;
            
        }
        
        String  month = String.valueOf(m) + '月';
        String  year= String.valueOf(y) + '年';
        AveragePrice__c av1 = new AveragePrice__c(
        Product__c = p1.Id,
            Company__c = '四川省迈克实业有限公司',
            AveragePrice__c = 1.0,
            Year__c = year,
            Month__c = month,
            PriceProvince__c = '四川省/西藏/重庆市'
            
        );
          AveragePrice__c av2 = new AveragePrice__c(
        Product__c = p2.Id,
            Company__c = '四川省迈克实业有限公司',
            AveragePrice__c = 1.0,
            Year__c = year,
            Month__c = month,
            PriceProvince__c = '四川省/西藏/重庆市'
            
        );
        insert new AveragePrice__c[] {av2,av1}; 


        PriceList__c pl = new PriceList__c();
        pl.Product__c = p1.Id;
        pl.SalesCode__c = '05';
        pl.Price__c = 100;
        pl.Account__c = acc.Id;
        pl.ApplicableCustomers__c = acc.Id;
        pl.Company__c = '四川省迈克实业有限公司';
        insert pl;

        //业务机会1
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        opp.CooperationMode__c = '整体配送';
        insert opp;

         //测算信息1
        Measure_Calculate__c mc = new Measure_Calculate__c(Opportunity__c = opp.Id);
        insert mc;

    


        Set<String> pcode = new Set<String>();
        pcode.add(p1.NCCode__c);
         Set<ID> pset = new Set<ID>();
        pset.add(p1.Id);

        ImportObject.matchProduct('四川省迈克实业有限公司', JSON.serialize(pcode),null, acc.Id, null,null  , '05');
        ImportObject.matchProductNo('四川省迈克实业有限公司', JSON.serialize(pcode),null , acc.Id, '05',null,false );
        ImportObject.getLastMothPrice(pcode,  '四川省迈克实业有限公司');
        ImportObject.getLastMothPrice(pset,  '四川省迈克实业有限公司');

        ImportObject.getPriceMap(pcode,  '四川省迈克实业有限公司');
        ImportObject.getPriceMap(pset,  '四川省迈克实业有限公司');
        ImportObject.getPriceMap(pset,  '四川省迈克实业有限公司',false);

        ImportObject.getPicklistValues('PriceList__c', 'SalesCode__c', false);
        ImportObject.getPriceListMap(pcode, acc.Id, '05','四川省迈克实业有限公司', false);
        ImportObject.getPriceListMap(pset, acc.Id, '05','四川省迈克实业有限公司', false);

        ImportObject.getObjectFieldsJSON('Account', true);


        // ImportObject.saveExelBlob('[[[{"1"}]]]');
        // ImportObject.clearExcelCache();
        ImportObject.getProudctMap(pcode);


        List<Map<String,String>> dataJson = new List<Map<String,String>>();
        Map<String,String> data = new Map<String,String>();

        data.put('nccode', p1.NCCode__c);
        data.put('sf_ter_account_id',acc.Id );
        data.put('sf_pay_account_id',acc.Id );

        data.put('regent_brand', '迈克生物');
        data.put('regent_cate1','试剂');
        data.put('regent_cate2','生化');

        data.put('owner_area','迈克实业' );
        data.put('owner_year_month','201801');
        data.put('sign_company','迈克生物');
        data.put('coop_start_date','2018-01-01');
        data.put('coop_end_date','2019-12-31');

        data.put('assign_2018','12.0');
        data.put('coop_year','2');
        data.put('is_all_brand','是');

        data.put('is_all_maccura_brand','是');
        data.put('sf_mc_no',[select Name from Measure_Calculate__c].Name );
        data.put('invname', '尿有形成份检测稀释液UPS');
        data.put('mcode','x00001');
        data.put('invtype', 'tt');
        data.put('task_resource', '合同规定');
        //data.put('is_trid_from_contract', '否');
        data.put('detail_note', '否');
        data.put('equip_note', '否');

        dataJson.add(data);
        String ires = ImportObject.importTask(EncodingUtil.urlEncode(JSON.serialize(dataJson), 'UTF-8'));
        System.debug(EncodingUtil.urlDecode(ires , 'UTF-8'));
        String s = ImportObject.getTaskImport();
        System.debug('ImportObjectTest==>'+s);
       TaskTrackingImport__c tti = [select Id from TaskTrackingImport__c limit 1  ];
       ImportObject.splitTaskFromImp(tti.Id);
       ImportObject.query('select id from Account limit 1 ');
       ImportObject.getSubRoleSet(new Set<Id>{[select Id from UserRole limit 1].Id});
       Map<String,String> searchMap = new Map<String,String>();
       searchMap.put('Brand__c', '迈克生物');
       ImportObject.getCateOrBrandFromProduct('Category0__c', JSON.serialize(searchMap));

       ImportObject.deleteImport(EncodingUtil.urlEncode(JSON.serialize(new List<String>{tti.Id}), 'UTF-8') );
        /*TestUtils.createUsers();
      u.FederationIdentifier = '1234T';
      u.CompanyName = 'Y-MKSY';*/
       TestUtils.createCity();
       TestUtils.createContact();
       TestUtils.createInst();
       TestUtils.createReceivableTemp();
       TestUtils.createOrder();
       TestUtils.createInst();
       TestUtils.createPrice();
       TestUtils.createDistrict();
       TestUtils.createEquipment();
       TestUtils.createProvince();
       TestUtils.createIntentProduct();







    }
}